home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-03-15 | 2.6 KB | 70 lines | [TEXT/gamI] |
- ; ----------------------------------------------------------------------------
- ; File: Vector.scm
- ; Description: vector manipulation functions
- ; Author: Raymond Laning at ART
- ; Created: 28-Apr-93
- ; Modified: 07-Dec-93 23:18:51 Raymond Laning
- ; Language: Scheme
- ; Status: Experimental (Do Not Distribute)
- ;
- ; (c) Copyright 1993, Advanced Robotic Technologies, Inc.
- ; All Rights Reserved.
- ; ----------------------------------------------------------------------------
-
- ;;;vector-copy copies the original vector into the destination vector
- ;;;starting at the start index in destination and stopping at the stop index
- ;;;in destination: the original vector starts at offset
- (define (vector-copy original destination start-index end-index offset)
- (do ((i start-index (+ i 1))
- (j offset (+ j 1)))
- ((> i end-index))
- (vector-set! destination i (vector-ref original j))))
-
- ;;;ditto, only for arrays
- (define (array-copy original destination start-index end-index offset flip?)
- (do ((i start-index (+ i 1))
- (j offset (+ j 1))
- (dims (get original 'dims)))
- ((> i end-index))
- (do ((k 0 (+ k 1)))
- ((>= k (cadr dims)))
- (array-set!
- destination i k
- (array-ref original (if flip? (- end-index j) j) k)))))
-
- ;;;vadd adds two vectors vec1 and vec2 provided they are of the same length
- (define (vadd vec1 vec2)
- (let* ((size (vector-length vec1))
- (out (make-vector size)))
- (if (= size (vector-length vec2))
- (do ((i 0 (+ 1 i)))
- ((>= i (vector-length vec1)) out)
- (vector-set! out i (+ (vector-ref vec1 i) (vector-ref vec2 i))))
- (error "different length vectors:"
- (vector-length vec1)
- (vector-length vec2)))))
-
- (define (scalar* scalar vec)
- (do ((i 0 (+ i 1)))
- ((>= i (vector-length vec)) vec)
- (vector-set! vec i (* scalar (vector-ref vec i)))))
-
- ;(define (cross-product vector1 vector2)
- ; (list (- (* (list-ref vector1 1) (list-ref vector2 2))
- ; (* (list-ref vector1 2) (list-ref vector2 1)))
- ; (- (* (list-ref vector1 2) (list-ref vector2 0))
- ; (* (list-ref vector1 0) (list-ref vector2 2)))
- ; (- (* (list-ref vector1 0) (list-ref vector2 1))
- ; (* (list-ref vector1 1) (list-ref vector2 0)))))
-
- (define (list-dot-product vector1 vector2)
- (apply + (map * vector1 vector2)))
-
- (define (list-magnitude vector)
- (sqrt (apply + (map (lambda (foo) (* foo foo)) vector))))
-
- (define (included-angle vector1 vector2)
- (let ((mag1 (list-magnitude vector1))
- (mag2 (list-magnitude vector2)))
- (acos (/ (list-dot-product vector1 vector2) (* mag1 mag2)))))
-